// 路由组件
import Vue from 'vue'
import Router from 'vue-router'
// import Login from '../src/components/Login'
Vue.use(Router)

const router = new Router({
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', component: () => import('@/components/Login') },
    {
      path: '/home',
      component: () => import('@/components/Home'),
      redirect: '/home/welcome',
      children: [
        { path: '/home/welcome', component: () => import('@/components/Welcome') },
        { path: '/home/users', component: () => import('@/components/user/Users') },
        { path: '/home/rights', component: () => import('@/components/power/Rights') },
        { path: '/home/roles', component: () => import('@/components/power/Roles') },
        { path: '/home/goods', component: () => import('@/components/goods/Cate') },
        { path: '/home/params', component: () => import('@/components/goods/Params') },
        { path: '/home/categories', component: () => import('@/components/goods/List') },
        { path: '/goods/add', component: () => import('@/components/goods/Add') },
        { path: '/home/orders', component: () => import('@/components/order/Order') },
        { path: '/home/reports', component: () => import('@/components/report/Report') }

      ]
    }
  ]
})
// 挂在路由导航守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  if (!sessionStorage.getItem('token')) return next('/login')
  next()
}
)
export default router
